// view/index/fangyi/fangyi.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');

Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    // huan: ['承诺书', '健康台账', '场所消杀','自检报告'],
    // huan: ['承诺书','自查报告'],
    huan: ['承诺书','自查报告'],

    currtab: 0,
    yuming: yuming,
    yiyao: '',
    heights: "",
    title: '',
    xuan: [],
    page: 1,
    // date: '开始时间', //开始
    endTime: '结束时间',
    starTime: '',
    endTimes: '',
    istime: false, //弹出时间筛选
    canvasHidden: true,
    ratio: 0, // 根据尺寸动态计算 1px换算成多少rpx
    windowWidth: 0, // 可使用窗口宽度
    windowHeight: 0, // 可使用窗口高度
    xiazai: false,
    canvasW: 350, //canvas宽
    canvasH: 574, //canvas高
    aaa: 1,
    qming: '',
    qqqm: false,
    epsituationImg: '', //生成之后的承诺书
    swiperIndex: 0,
    yi_yiqin: '', //疫情是否签了名 epsituationImg
    wuyi_yiqin: '', //疫情是否签了名 epsituationImg
    ling_yiqin: '', //零售是否签了名 retailImg
    wuling_yiqin: '', //零售是否签了名 retailImg
    qixie_yiqin: '', //器械是否签了名  apparatusImg
    wuqixie_yiqin: '', //器械是否签了名  apparatusImg
    is_shui: '', //是谁
    chengnus: '', //承诺书本地路径
    lingshou: '', //零售本地路径
    qixie: '', //器械本地路径
    qianming_id: '', //签名的id
    qianming_tu: '', //签字的图
    wuqianming_tu: '', //签字图没域名
    fromid: '', //存的是哪个
    gao: '',
    iaas: false,
    taiz_total: '',
    xiaos_total: '',
    yearcount:"",
    shopReportList:[],
    total:'',
    image:[],
    datesss: '',
    datessss:'',
    zixchafalse:false

  },
  // 隐藏签名
  yin_qian() {
    this.setData({
      qqqm: false
    })
  },
  gozicha(){
    console.log(12);
    wx.navigateTo({
      url: '/page_one/zichabaogao/zichabaogao',
    })
  },
  // 重新签名
  chongxin(e) {
    var shuxing = e.currentTarget.dataset.shuxing
    this.setData({
      qqqm: !this.data.qqqm,
      is_shui: shuxing
    })
    // epsituationImg  疫情   retailImg  零售 apparatusImg 器械
    var data = {}
    if (shuxing == "epsituationImg") {
      data = {
        shopId: wx.getStorageSync('shopId'),
        epsituationImg: ''
      }
    }
    if (shuxing == "retailImg") {
      data = {
        shopId: wx.getStorageSync('shopId'),
        retailImg: ''
      }
    }
    if (shuxing == "apparatusImg") {
      data = {
        shopId: wx.getStorageSync('shopId'),
        apparatusImg: ''
      }
    }
    // var that = this
    // this.myRequest(yuming + 'shop/shopSaveBossBg', {
    //   shopId: wx.getStorageSync('shopId'),
    //   epsituationImg: ''
    // }, "POST").then(res => {
    //   wx.setStorageSync('yqsign', '')
    //   that.chengns()
    //   setTimeout(function () {
    //     that.setData({
    //       qqqm: true
    //     })
    //   }, 1000)
    // })
  },
  // 没有签名时打开签名
  qianmi(e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    var fromid = e.currentTarget.dataset.fromid
    this.setData({
      qianming_id: id,
      fromid: fromid,
      iaas: true
    })
    console.log(this.data.qianming_id);
    console.log(this.data.fromid);
    this.setData({
      qqqm: !this.data.qqqm
    })
    // if (!this.data.qqqm) {
    //   this.chengns()
    // }
  },
  // 修改签名
  xiugaiqm() {
    this.setData({
      qqqm: !this.data.qqqm,
      isshw: true
    })
    // this.chengns()
  },
  // 添加
  jias() {
    wx.navigateTo({
      url: '/page_two/addmian/addmian',
    })
  },
  // tab切换
  qies(e) {
    var index = e.currentTarget.dataset.currtab
    this.setData({
      currtab: index,
      page: 1,
      date: '开始时间',
      endTime: '结束时间'
    })
    if (this.data.currtab == 0) {
    //   this.chengns()
    this.getChengLuoBooK()

    }
    // if (this.data.currtab == 1) {
    //   this.yqlist()
    // }
    // if (this.data.currtab == 2) {
    //   this.dianmian()
    // }
    // 自检报告
    if (this.data.currtab == 1) {
      this.zijianreport()
    }
  },
  bindyue(e) {
    if (e.detail.value > new Date().getFullYear()) {
      wx.showToast({
        title: '年份未到~',
        icon: 'none'
      })
      return
    } else {
      this.setData({
        datesss: e.detail.value
      })
      this.zijianreport();
    }
  },
  zijianreport(){
    var url = '',
    url = 'Jinghexincheng/zijianbaogao_list'
    this.myRequest(yuming + url, {
      shopId: wx.getStorageSync('shopId'),
      year:this.data.datesss ,
      page:1
    }, "POST").then(res => {
     
      if (res.data.code == 200) {
      //  this.shopReportList = res.data.data
       this.setData({
        shopReportList: res.data.data
      })
       console.log(this.shopReportList);
      //  shopReportList.length
      console.log(this.shopReportList.length);
      }
    })
  },
  gonggao(e) {
    var url = e.currentTarget.dataset.yj_type
    wx.showLoading({
      title: '正在打开中',
    })
    var hou = url.slice(24)
    console.log(hou)
    var s = hou.indexOf(".")
    var type = hou.substring(s + 1) //下划线之后
    console.log(type)
    // var url = url.slice 
    var that = this
    wx.downloadFile({
      url: url,
      success(res) {
        var filePath = res.tempFilePath
        console.log(url)
        wx.openDocument({
          filePath: filePath,
          fileType: type,
          success: function (res) {
            wx.hideLoading({
              success: (res) => {},
            })
          },
          fail(err) {
            console.log(err)
            wx.hideLoading({
              success: (res) => {},
            })
            wx.showToast({
              title: '打开失败',
              icon: 'none'
            })
          }
        })
      },
      fail(err) {
        console.log(22)
        wx.hideLoading({
          success: (res) => {},
        })
        wx.showToast({
          title: '打开失败',
          icon: 'none'
        })
      }
    })
  },
  tan() {
    this.setData({
      istime: !this.data.istime
    })
  },
  que() {
    // if (this.data.currtab == 1) {
    //   this.yqlist()
    // } 
    if (this.data.currtab == 1) {
      this.zijianreport()
    } 
    // else {
    //   this.dianmian()
    // }
    this.setData({
      istime: !this.data.istime
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.xuan
    this.setData({
      page: (this.data.page) + 1
    })
    // if (this.data.currtab == 0) {
    //   this.yqlist()
    // } 
    if (this.data.currtab == 1) {
      this.zijianreport()
    } 
    // else {
    //   this.dianmian()
    // }
  },
  // 年份
  year(){
    this.yearcount = new Date()
  },
  // 店面
  dianmian() {
    var that = this
    this.myRequest(yuming + 'shop/shopSelectShopKilllog', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page,
      starTime: that.data.starTime,
      endTime: that.data.endTimes
    }, "POST").then(res => {
      that.setData({
        xiaos_total: res.data.total
      })
      shu = res.data.data
      if (that.data.page != 1) {
        if (shu.length == 0) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          that.setData({
            dianmian: []
          })
        }
      }
      that.setData({
        dianmian: shuzong.concat(shu)
      })
      for (let i = 0; i < that.data.dianmian.length; i++) {
        let xdcs = that.data.dianmian[i].disSite
        if (xdcs.slice(-1) == ',') {
          xdcs = xdcs.slice(0, xdcs.length - 1);
          that.data.dianmian[i].disSite = xdcs;
        }
      }
      that.setData({
        dianmian: that.data.dianmian
      })
    })
  },
  // 疫情列表
  yqlist() {
    var that = this
    this.myRequest(yuming + 'shop/shopSelectKilllog', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page,
      starTime: that.data.starTime,
      endTime: that.data.endTimes
    }, "POST").then(res => {
      shu = res.data.data
      that.setData({
        taiz_total: res.data.total
      })
      if (that.data.page != 1) {
        if (shu.length == 0) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          that.setData({
            xuan: []
          })
        }
      }
      that.setData({
        xuan: shuzong.concat(shu)
      })
    })
  },
  // 删除
  delete(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '否',
      confirmText: '是',
      success(res) {
        if (res.confirm) {
          console.log("是")
          that.shan(id)
        } else {
          console.log("否")
        }
      }
    })
  },
  deletereport(e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    var that = this
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '否',
      confirmText: '是',
      success(res) {
        if (res.confirm) {
          console.log("是")
          that.shan(id)
        } else {
          console.log("否")
        }
      }
    })
  },
  shan(id) {
    var that = this
    var url = ''
    // if (that.data.currtab == 1) {
    //   url = 'shop/shopDelKilllog'
    // } else {
    //   url = 'shop/shopDelShopKilllog'
    // }
    if(that.data.currtab == 1){
      url = 'Jinghexincheng/zijianbaogao_del'
    }
    this.myRequest(yuming + url, {
      id: id,
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        // if (that.data.currtab == 1) {
        //   that.yqlist()
        // } else {
        //   that.dianmian()
        // }
        that.zijianreport()
      }
    })
  },
  duo_fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    wx.previewImage({
        current: img,
        urls: list
    })
},
  //放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  xinzeng(e) {
    this.setData({
      date: '开始时间',
      endTime: '结束时间',
      page: 1
    })
    // if (this.data.currtab == 1) {
    //   wx.navigateTo({
    //     url: '/page_two/addyi/addyi',
    //   })
    // } if(this.data.currtab == 2) {
    //   wx.navigateTo({
    //     url: '/page_two/addmian/addmian',
    //   })
    // }
    if(this.data.currtab == 1) {
      wx.navigateTo({
        url: '/page_two/zijianreport/zijianreport',
      })
    }
  },
  // 历史承诺书跳转
  goHistory(){
    wx.navigateTo({
      url: '/page_other/historybook/historybook',
    })
    // this.getHistoryList()
  },
  getHistoryList(){
    var url = '',
    url = 'Jinghexincheng/chengnuoshu_list'
    this.myRequest(yuming + url, {
      shopId: wx.getStorageSync('shopId'),
      year:2023,
      page:1
    }, "POST").then(res => {
     
      if (res.data.code == 200) {
        console.log(res);
       this.setData({
          total:res.data.total,
          image:res.data.data[0].image
       })
      }
    })
  },
  // 选择开始时间
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value,
      starTime: e.detail.value
    })
  },
  // 选择结束时间
  endTime: function (e) {
    this.setData({
      endTime: e.detail.value,
      endTimes: e.detail.value,
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHistoryList()
    console.log(this.data.epsituationImg)
    var test = new Date();
    var year = test.getFullYear();
    var month = test.getMonth() + 1
    var ri = test.getDate()
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      gao: wx.getMenuButtonBoundingClientRect().top + 50,
      title: options.title,
      // date: year+"-"+month+"-"+ri
      yearcount:year,
    })
    this.getChengLuoBooK()
    if(wx.getStorageSync('jinghe_id') == 176){
      this.setData({
        zixchafalse:true
      })
    }
  },
  downLoad(e) {
    var that = this;
    wx.showLoading({
      title: '正在生成图片',
    })
    // 背景 承诺书
    wx.downloadFile({
      url: that.data.cns.yiqingchengnuoshu,
      success: function (res3) {
        console.log(44444)
        console.log(res3)
        that.setData({
          chengnus: res3.tempFilePath
        })
        // 零售
        wx.downloadFile({
          url: that.data.cns.yaopinlingshou,
          success: function (res3) {
            that.setData({
              lingshou: res3.tempFilePath
            })
            // 器械
            wx.downloadFile({
              url: that.data.cns.yiliaoqixie,
              success: function (res3) {
                that.setData({
                  qixie: res3.tempFilePath
                })
                that.createCanvasShareImage();
              }
            })
          }
        })
        // 签名
        // if (that.data.qming != '') {
        //   console.log(121111111111)
        // wx.downloadFile({
        //   url: that.data.qming,
        //   success: function (res3) {
        //     that.setData({
        //       qian: res3.tempFilePath
        //     })
        //     that.createCanvasShareImage();
        //   }
        // })
        // } else {
        //   console.log(3333333333333)
        //   that.createCanvasShareImage();
        // }
      }
    })
  },
  // 绘制
  createCanvasShareImage() {
    let context = wx.createCanvasContext('shareCanvas' + this.data.aaa);
    let canvasWidthPx = 700 / this.data.ratio;
    var windowWidth = this.data.windowWidth //手机宽
    var windowHeight = this.data.windowHeight //手机搞
    // x轴
    var pagex = 80
    var pagey = 240
    // canvas背景色
    context.fillStyle = '#fff';
    context.fillRect(0, 0, this.data.canvasW, this.data.canvasH);
    // 承诺书
    context.drawImage(this.data.chengnus, 0, 0, this.data.canvasW, this.data.canvasH);
    // 零售
    // context.drawImage(this.data.lingshou, 0, 0, this.data.canvasW, this.data.canvasH);
    // 器械
    // context.drawImage(this.data.qixie, 0, 0, this.data.canvasW, this.data.canvasH);
    // 店铺名
    context.fillStyle = '#000';
    context.setFontSize(16);
    context.fillText(this.data.dianpu, 90, 99);
    // 时间
    context.fillStyle = '#000';
    context.setFontSize(14);
    context.fillText(this.data.shijian, this.data.canvasW - 110, this.data.canvasH - 63);
    //签名
    if (this.data.epsituationImg != '') {
      context.drawImage(this.data.epsituationImg, this.data.canvasW - 100, this.data.canvasH - 130, 90, 50);
    }
    context.draw();
    wx.hideLoading({})
    // this.setData({
    //   xiazai: true
    // })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.getSystemInfo({
      success: res => {
        // console.log(res);
        this.setData({
          windowWidth: res.windowWidth * 1.5,
          windowHeight: res.windowHeight,
        });
        this.setData({
          // 屏幕宽度 375px = 750rpx，1px=2rpx
          // 1px = （750 / 屏幕宽度）rpx；
          // 1rpx = （屏幕宽度 / 750）px;
          ratio: 750 / this.data.windowWidth
        });
      }
    });
  },
  // 签名
  bindtouchstart: function (e) {
    this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y);
    this.setData({
      iaas: true,
    })
  },
  clear: function () {
    // const context = wx.createCanvasContext('firstCanvas' + this.data.aaa);
    // context.setFillStyle('#fff')
    // context.fillRect(0, 0, 350, 200)
    // context.setLineWidth(3)
    // this.setData({
    //   context
    // });
    // context.draw()
    this.data.context.draw();
    this.data.context.setFillStyle('#fff')
    this.data.context.setLineWidth(3)
    this.data.context.fillRect(0, 0, 350, 200)
  },
  bindtouchmove: function (e) {
    this.setData({
      iaas: true,
    })
    // console.log(e.changedTouches)
    this.data.context.lineTo(e.changedTouches[0].x, e.changedTouches[0].y);
    this.data.context.stroke();
    this.data.context.draw(true);
    this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y);
  },
  export: function () {
    wx.showLoading({
      title: '签字中',
    })
    let that = this;
    that.data.context.fillStyle = '#ffffff'
    that.data.context.draw(true, function () {
      setTimeout(function () {
        wx.canvasToTempFilePath({
          fileType: 'png',
          x: 0,
          y: 0,
          width: 350,
          height: 200,
          destWidth: 250,
          destHeight: 100,
          quality: 1,
          canvasId: 'firstCanvas' + that.data.aaa,
          success(res) {
            console.log(222)
            let {
              tempFilePath
            } = res;
            console.log(tempFilePath)
            wx.uploadFile({
              url: yuming + 'Besall/Upload',
              filePath: tempFilePath,
              name: 'file',
              formData: {

              },
              success(res) {
                console.log(333)
                var data = JSON.parse(res.data)
                var qianming = data.httpUrl + data.imgUrl
                var wuurl = data.imgUrl
                that.setData({
                  qianming_tu: qianming,
                  wuqianming_tu: data.imgUrl,
                })
                that.setData({
                  qqqm: false
                })
                that.queqian()
                // wx.setStorageSync('yqsign', qianming);
                // wx.showToast({
                //   title: '签名成功',
                //   icon: 'none'
                // })
                // that.setData({
                //   qqqm: false,
                // })
                // that.chengns()
                // setTimeout(function () {
                //   that.shengcnuoshu()
                // }, 1000)
              }
            })
          },
          fail(err) {
            console.log(err)
            wx.showToast({
              title: err,
              icon: 'none',
              duration: 2000
            })
          }
        })
      }, 1000)
    })
  },
  // 合成签名的接口
  queqian() {
    this.myRequest(yuming + 'Besall/upload_imgs_compose', {
      shopId: wx.getStorageSync('shopId'),
      id: this.data.qianming_id,
      url_b: this.data.wuqianming_tu
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        var that = this
        var data = res.data
        var qianming = data.httpUrl + data.imgUrl
        var wuurl = data.imgUrl
        // if (that.data.fromid == 'yiqingchengnuoshu') {
        //   that.setData({
        //     wuyi_yiqin: wuurl,
        //     yi_yiqin: qianming,
        //   })
        //   setTimeout(function () {
        //     that.tijiao()
        //   }, 1000)
        // }
        // if (that.data.ulist[0].cnsId == 2) {
          that.setData({
            wuling_yiqin: wuurl,
            // ling_yiqin: qianming,
          })
          setTimeout(function () {
              console.log(that.data.fromid);
              if(that.data.fromid === undefined){
                  that.tijiao()
                }else{
                    that.re_sign()
                }
          }, 1000)
        // }
        // if (that.data.ulist[0].cnsId == 3) {
        //   that.setData({
        //     wuqixie_yiqin: wuurl,
        //     qixie_yiqin: qianming,
        //   })
        //   setTimeout(function () {
        //     that.tijiao()
        //   }, 1000)
        // }

      }
    })
  },
//   tijiao() {
//     var that = this
//     var yi_yiqin = ''
//     var ling_yiqin = ''
//     var qixie_yiqin = ''
//     var data = {}
//     // if (that.data.fromid == 'yiqingchengnuoshu') {
//       data = {
//         shopId: wx.getStorageSync('shopId'),
//         epsituationImg: that.data.wuyi_yiqin
//       }
//       this.myRequest(yuming + 'shop/shopSaveBossBg', data, "POST").then(res => {
//         wx.showToast({
//           title: res.data.msg,
//           icon: 'none'
//         })
//         if (res.data.code == 200) {
//           setTimeout(function () {
//             that.data.aaa++;
//             that.setData({
//               aaa: that.data.aaa,
//               ling_yiqin: '',
//               fromid: '',
//               qianming_id: '',
//               qianming_tu: '',
//               qixie_yiqin: '',
//               wuqianming_tu: ''
//             })
//             // that.chengns()
//           }, 1000)

//         }
//       })
//     // }
//     if (that.data.fromid == 'yaopinlingshou') {
//       data = {
//         shopId: wx.getStorageSync('shopId'),
//         retailImg: that.data.wuling_yiqin
//       }
//       this.myRequest(yuming + 'shop/shopSaveBossBg', data, "POST").then(res => {
//         wx.showToast({
//           title: res.data.msg,
//           icon: 'none'
//         })
//         if (res.data.code == 200) {
//           setTimeout(function () {
//             that.data.aaa++;
//             that.setData({
//               aaa: that.data.aaa,
//               ling_yiqin: '',
//               fromid: '',
//               qianming_id: '',
//               qianming_tu: '',
//               qixie_yiqin: '',
//               wuqianming_tu: ''
//             })
//             // that.chengns()
//           }, 1000)

//         }
//       })
//     }
//     if (that.data.fromid == 'yiliaoqixie') {
//       data = {
//         shopId: wx.getStorageSync('shopId'),
//         apparatusImg: that.data.wuqixie_yiqin
//       }
//       this.myRequest(yuming + 'shop/shopSaveBossBg', data, "POST").then(res => {
//         wx.showToast({
//           title: res.data.msg,
//           icon: 'none'
//         })
//         if (res.data.code == 200) {
//           setTimeout(function () {
//             that.data.aaa++;
//             that.setData({
//               aaa: that.data.aaa,
//               ling_yiqin: '',
//               fromid: '',
//               qianming_id: '',
//               qianming_tu: '',
//               qixie_yiqin: '',
//               wuqianming_tu: ''
//             })
//             that.chengns()
//           }, 1000)

//         }
//       })
//     }
//   },
  tijiao(){
    this.myRequest(yuming + 'Jinghexincheng/chengnuoshu_add',{
        shopId:wx.getStorageSync('shopId'),
        image:this.data.wuling_yiqin,
        year:this.data.yearcount,
        cnsId:this.data.qianming_id
    },"POST").then(res =>{
        wx.showToast({
          title: res.data.msg,
          icon:"none"
        })
    this.getChengLuoBooK()

    })
  },
//   重新签名
    re_sign(){
        this.myRequest(yuming + 'Jinghexincheng/chengnuoshu_save',{
            shopId:wx.getStorageSync('shopId'),
            image:this.data.wuling_yiqin,
            year:this.data.yearcount,
            cnsId:this.data.qianming_id,
            id:this.data.fromid
        },"POST").then(res =>{
            wx.showToast({
              title: res.data.msg,
              icon:"none"
            })
        this.getChengLuoBooK()
        })
    },
  swiperChange(e) {
    console.log(e)
    var index = e.detail.current
    let that = this
    that.setData({
      swiperIndex: index,
    })
    console.log(that.data.swiperIndex)
    if (this.data.ulist[this.data.swiperIndex].data != null) {
      this.setData({
        sunimg: this.data.ulist[this.data.swiperIndex].data.qrUrl
      })
      console.log(this.data.sunimg)
    }
  },
  // 获取承诺书
  chengns() {
    var that = this
    this.myRequest(yuming + 'Besall/backEpsituationBgimg', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      var data = res.data.data
      var das = res.data
      // 合成之后的
      if (data[0].fromid == 'yiqingchengnuoshu') {
        data[0].tagers = '防疫'
        data[0].isqian = das.epsituationImg
        data[1].tagers = '零售'
        data[1].isqian = das.retailImg
        data[2].tagers = '器械'
        data[2].isqian = das.apparatusImg
        // if (wx.getStorageSync('jinghe_id') == 176) {
        data = data.slice(1)
        // }
        that.setData({
          yi_yiqin: das.epsituationImg, //防疫 合成之后的
          ling_yiqin: das.retailImg, //零售
          qixie_yiqin: das.apparatusImg, //器械
        //   ulist: data
        })
      } else {
        data[0].tagers = '零售'
        data[0].isqian = das.retailImg
        data[1].tagers = '器械'
        data[1].isqian = das.apparatusImg
        that.setData({
          yi_yiqin: das.epsituationImg, //防疫 合成之后的
          ling_yiqin: das.retailImg, //零售
          qixie_yiqin: das.apparatusImg, //器械
        //   ulist: data
        })
      }

      that.setData({
        cns: res.data.data,
        shijian: res.data.day,
        dianpu: res.data.shopName,
        qming: wx.getStorageSync('yqsign'),

      })

      // 签名
      const context = wx.createCanvasContext('firstCanvas' + this.data.aaa);
      context.setFillStyle('#fff')
      context.fillRect(0, 0, 350, 200)
      context.setLineWidth(3)
      this.setData({
        context
      });
      context.draw()
    })
  },

  // 承诺书   修改之后的
  getChengLuoBooK(){
    this.myRequest(yuming + 'Besall/shopCnsByshopId',{
      shopId: wx.getStorageSync('shopId'),
      year:this.data.yearcount
    },"POST").then(res=>{
    //   console.log(res);
      this.setData({
          ulist: res.data.data
      })
      console.log(res.data.data);
    })
  },
  // 确定生成承诺书
  // shengcheng() {
  //   var that = this
  //   that.shengcnuoshu()

  // },
  // 生成承诺书
  shengcnuoshu() {
    wx.showLoading({
      title: '合成中...',
    })
    var that = this
    setTimeout(function () {
      wx.canvasToTempFilePath({
        canvasId: 'shareCanvas' + that.data.aaa,
        success: (res) => {
          console.log('canvasToTempFilePath： ', res);
          that.data.aaa++;
          that.setData({
            aaa: that.data.aaa
          })
          var url = res.tempFilePath
          wx.uploadFile({
            url: yuming + 'Besall/Upload',
            filePath: url,
            name: 'file',
            formData: {

            },
            success(res) {
              console.log(333)
              var data = JSON.parse(res.data)
              var img = data.imgUrl
              console.log(img)
              that.setData({
                epsituationImg: img,
              })
              wx.hideLoading({
                success: (res) => {
                  that.tijiao()
                },
              })
            }
          })

        }
      })
    }, 1000)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      yiyao: wx.getStorageSync('stryId')
    })
    this.yqlist()
    this.dianmian()
    // 获取承诺数
    this.chengns()
    this.year()
 
      this.zijianreport()
    this.getChengLuoBooK()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})